package o;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.ImageView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.GlideException;
import java.io.File;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import o.dky.a;

public final class eqx {
    private static HashMap<String, Integer> ˋ;
    private static int ॱ = 0;

    static class b implements zn {
        private final String ˋ;
        private final ImageView ˏ;

        public b(ImageView imageView, String str) {
            this.ˏ = imageView;
            this.ˋ = str;
        }

        public boolean ॱ(@Nullable GlideException glideException, Object obj, zz zzVar, boolean z) {
            if (this.ˋ != null) {
                erm.ˏ().ˋ(this.ˏ, this.ˋ);
            } else {
                if (glideException != null) {
                    Logger.ˏ("ImageUtils", "ImageRequest onException: " + glideException.toString() + " , model : " + obj);
                } else {
                    Logger.ˏ("ImageUtils", "ImageRequest onException! model : " + obj);
                }
                eso.ॱ(glideException, obj);
            }
            return true;
        }

        public boolean ˎ(Object obj, Object obj2, zz zzVar, rz rzVar, boolean z) {
            return false;
        }
    }

    static class c extends aac<Bitmap> {
        private boolean ˊ = false;
        private String ˎ;
        private ImageView ˏ;
        private eqz ॱ;

        public /* synthetic */ void onResourceReady(@NonNull Object obj, @Nullable aaf o_aaf) {
            ˊ((Bitmap) obj, o_aaf);
        }

        public c(ImageView imageView, eqz o_eqz, String str) {
            this.ॱ = o_eqz;
            this.ˏ = imageView;
            this.ˎ = str;
        }

        public c(ImageView imageView, eqz o_eqz, boolean z) {
            this.ॱ = o_eqz;
            this.ˏ = imageView;
            this.ˊ = z;
        }

        public void ˊ(@NonNull Bitmap bitmap, @Nullable aaf<? super Bitmap> o_aaf__super_android_graphics_Bitmap) {
            if (this.ˏ != null) {
                Object tag = this.ˏ.getTag(this.ˏ.getId());
                if (tag != null && this.ˎ != null && this.ˎ.equals(tag.toString())) {
                    this.ˏ.setImageBitmap(bitmap);
                    if (this.ॱ != null) {
                        this.ॱ.ॱ(bitmap);
                    }
                }
            } else if (this.ॱ != null) {
                this.ॱ.ॱ(bitmap);
            }
        }

        public void onLoadFailed(@Nullable Drawable drawable) {
            super.onLoadFailed(drawable);
            if (this.ˊ) {
                Logger.ˏ("ImageUtils", "clear current image load task.");
                if (this.ˏ != null) {
                    Glide.ˏ(this.ˏ).ˎ(this);
                }
            }
            if (this.ॱ != null) {
                this.ॱ.ॱ(null);
            }
        }
    }

    public enum d {
        PIC_TYPE_GIF,
        PIC_TYPE_NORMAL,
        PIC_TYPE_UNKNOWN
    }

    static class e {
        private boolean ʼ;
        private zn ʽ;
        private d ˊ;
        private int ˋ;
        private zp ˎ;
        private si[] ˏ;
        private int ॱ;
        private String ॱॱ;

        private e() {
            this.ॱ = -1;
            this.ˋ = -1;
            this.ˊ = d.PIC_TYPE_NORMAL;
            this.ʽ = new era();
        }
    }

    public static void ॱ(ImageView imageView, String str, @DrawableRes int i) {
        e eVar = new e();
        eVar.ʽ = new era();
        eVar.ॱॱ = str;
        if (a.ˎˎ != i) {
            eVar.ˎ = (zp) new zp().ˎ(i);
        }
        ˋ(imageView, eVar);
    }

    public static void ˎ(ImageView imageView, String str) {
        ˎ(imageView, str, null, null, d.PIC_TYPE_NORMAL, new si[0]);
    }

    public static void ˏ(ImageView imageView, String str, String str2) {
        ˎ(imageView, str, str2, null, d.PIC_TYPE_NORMAL, new si[0]);
    }

    public static void ˊ(ImageView imageView, String str, String str2, d dVar) {
        ˎ(imageView, str, str2, null, dVar, new si[0]);
    }

    public static void ˏ(ImageView imageView, String str, String str2, si... siVarArr) {
        ˎ(imageView, str, str2, null, d.PIC_TYPE_NORMAL, siVarArr);
    }

    public static void ˎ(ImageView imageView, String str, String str2, String str3) {
        if (imageView == null || str == null || str2 == null || str3 == null) {
            Logger.ˎ("ImageUtils", "asynLoadImagePackage param is null");
            return;
        }
        Context context = imageView.getContext();
        e eVar = new e();
        eVar.ॱॱ = str;
        Bitmap ˋ = erm.ˏ().ˋ("GetLocalAppIcon_PackageName_" + str3);
        if (ˋ != null) {
            eVar.ˎ = (zp) new zp().ˎ(new BitmapDrawable(context.getResources(), ˋ));
        } else {
            eVar.ˎ = ॱ(context, str2);
            eVar.ʽ = new b(imageView, str3);
        }
        ˋ(imageView, eVar);
    }

    public static void ॱ(Context context, String str, eqz o_eqz) {
        zn o_era = new era();
        ro ॱ = eqy.ॱ(context, str);
        if (ॱ != null) {
            ॱ.ॱ(o_era).ˏ(new c(null, o_eqz, str));
        }
    }

    public static void ˎ(ImageView imageView, String str, String str2, eqz o_eqz, boolean z) {
        if (imageView == null || str == null || str2 == null || o_eqz == null) {
            Logger.ˎ("ImageUtils", "asynLoadImage param is null");
            return;
        }
        Context context = imageView.getContext();
        imageView.setTag(imageView.getId(), str);
        ro ˏ = eqy.ˏ(context, str, z);
        if (ˏ != null) {
            ˏ(ˏ, str2, imageView);
            ˏ.ॱ(new era()).ˏ(new c(imageView, o_eqz, str));
        }
    }

    public static void ˎ(Context context, String str, eqz o_eqz, boolean z) {
        zn o_era = new era();
        ro ॱ = eqy.ॱ(context, str);
        if (ॱ != null) {
            ॱ.ॱ(o_era).ˏ(new c(null, o_eqz, z));
        }
    }

    public static void ˏ(ImageView imageView, String str) {
        ˎ(imageView, str, null);
    }

    public static void ˎ(ImageView imageView, String str, String str2) {
        Context context;
        e eVar = new e();
        eVar.ˊ = d.PIC_TYPE_GIF;
        eVar.ॱॱ = str;
        if (imageView != null) {
            context = imageView.getContext();
        } else {
            context = null;
        }
        eVar.ˎ = ॱ(context, str2);
        eVar.ʽ = null;
        ˋ(imageView, eVar);
    }

    public static void ॱ(ImageView imageView, String str, String str2) {
        if (imageView == null) {
            Logger.e("ImageUtils", "asyncLoadGifIcon imageView is null");
            return;
        }
        Context context = imageView.getContext();
        int color = context.getResources().getColor(o.dky.d.ˎ);
        float dimension = context.getResources().getDimension(o.dky.c.ˏ);
        ˋ(imageView, str, str2, epv.ˏॱ(), color, dimension);
    }

    public static void ˋ(ImageView imageView, String str, String str2, int i, int i2, float f) {
        if (imageView == null || TextUtils.isEmpty(str) || i <= 0) {
            Logger.e("ImageUtils", "asyncLoadGifIcon param is null");
            return;
        }
        ro ॱ;
        try {
            ॱ = Glide.ˏ(imageView.getContext()).ʼ().ˎ(str).ॱ((zp) ((zp) new zp().ˊ(tf.ˋ)).ˏ(new ckn(i, i2, f)));
        } catch (IllegalArgumentException e) {
            Logger.e("ImageUtils", "asyncLoadGifIcon: glide builder IllegalArgumentException.");
            ॱ = null;
        }
        if (ॱ == null) {
            Logger.ˏ("ImageUtils", "asyncLoadGifIcon builder is null.");
            return;
        }
        if (!TextUtils.isEmpty(str2)) {
            ॱ = ˏ(ॱ, str2, imageView);
        }
        ॱ.ˏ(imageView);
    }

    public static Bitmap ˋ(Context context, String str) {
        try {
            return (Bitmap) Glide.ˏ(context).ॱ().ˎ(str).ॱ(Integer.MIN_VALUE, Integer.MIN_VALUE).get(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Logger.e("ImageUtils", "loadImage: " + e.toString());
        } catch (ExecutionException e2) {
            Logger.e("ImageUtils", "loadImage: " + e2.toString());
        } catch (TimeoutException e3) {
            Logger.e("ImageUtils", "loadImage: " + e3.toString());
        } catch (IllegalArgumentException e4) {
            Logger.ˏ("ImageUtils", "loadImage: " + e4.toString());
        }
        return null;
    }

    public static File ˎ(Context context, String str) {
        try {
            return (File) Glide.ˏ(context).ˏ(str).ˏ(Integer.MIN_VALUE, Integer.MIN_VALUE).get(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Logger.e("ImageUtils", "loadImageFile: " + e.toString());
        } catch (ExecutionException e2) {
            Logger.e("ImageUtils", "loadImageFile: " + e2.toString());
        } catch (TimeoutException e3) {
            Logger.e("ImageUtils", "loadImageFile: " + e3.toString());
        } catch (IllegalArgumentException e4) {
            Logger.ˏ("ImageUtils", "loadImageFile: " + e4.toString());
        }
        return null;
    }

    public static Bitmap ˏ(Bitmap bitmap, double d, double d2) {
        float width = (float) bitmap.getWidth();
        float height = (float) bitmap.getHeight();
        Matrix matrix = new Matrix();
        matrix.postScale(((float) d) / width, ((float) d2) / height);
        return Bitmap.createBitmap(bitmap, 0, 0, (int) width, (int) height, matrix, true);
    }

    public static void ॱ(HashMap<String, Integer> hashMap) {
        ˋ = hashMap;
    }

    public static void ˏ(int i) {
        ॱ = i;
    }

    protected static void ˎ(ImageView imageView, String str, String str2, String str3, d dVar, si... siVarArr) {
        Context context = null;
        e eVar = new e();
        eVar.ॱॱ = str;
        eVar.ˊ = dVar;
        eVar.ˏ = siVarArr;
        if (imageView != null) {
            context = imageView.getContext();
        }
        eVar.ˎ = ॱ(context, str2);
        if (!TextUtils.isEmpty(str3)) {
            eVar.ʽ = new b(imageView, str3);
        }
        ˋ(imageView, eVar);
    }

    private static void ˋ(ImageView imageView, e eVar) {
        if (imageView != null) {
            ro ˏ = ˏ(imageView.getContext(), eVar);
            if (ˏ != null) {
                ˏ.ˏ(imageView);
            }
        }
    }

    private static ro ˏ(Context context, e eVar) {
        if (eVar == null) {
            return null;
        }
        ro ˊ;
        if (eVar.ˊ == d.PIC_TYPE_GIF) {
            ˊ = eqy.ˊ(context, eVar.ॱॱ, eVar.ʼ);
        } else if (eVar.ˊ == d.PIC_TYPE_NORMAL) {
            ˊ = eqy.ˏ(context, eVar.ॱॱ, eVar.ʼ);
        } else {
            ˊ = eqy.ॱ(context, eVar.ॱॱ, eVar.ʼ);
        }
        if (ˊ == null) {
            Logger.ˏ("ImageUtils", "asynLoadImage builder is null.");
            return null;
        }
        if (eVar.ˎ != null) {
            ˊ.ॱ(eVar.ˎ);
        }
        if (eVar.ॱ > 0 && eVar.ˋ > 0) {
            ze zpVar = new zp();
            zpVar.ˊ(eVar.ॱ, eVar.ˋ);
            ˊ.ॱ(zpVar);
        }
        if (eVar.ˏ != null) {
            for (si siVar : eVar.ˏ) {
                if (siVar != null) {
                    ˊ = ˊ.ॱ(zp.ˎ(siVar));
                }
            }
        }
        if (eVar.ʽ != null) {
            return ˊ.ॱ(eVar.ʽ);
        }
        return ˊ;
    }

    public static <T> ro<T> ˏ(ro<T> roVar, String str, ImageView imageView) {
        return roVar.ॱ(ॱ(imageView.getContext(), str));
    }

    private static zp ॱ(Context context, String str) {
        zp zpVar = new zp();
        if (context == null) {
            return zpVar;
        }
        int i = 0;
        if (ˏ(str)) {
            String ॱ = ॱ(str);
            if (ˋ != null) {
                Integer num = (Integer) ˋ.get(ॱ);
                i = num != null ? num.intValue() : ॱ;
            }
        }
        zp zpVar2 = i != 0 ? evf.ˋ(context) ? (zp) zpVar.ˎ((Drawable) fmw.ˏ(context, i, "drawable")) : (zp) zpVar.ˎ(i) : zpVar;
        return zpVar2;
    }

    private static boolean ˏ(String str) {
        if (!TextUtils.isEmpty(str) && "iconflag".equals(str)) {
            return false;
        }
        return true;
    }

    private static String ॱ(String str) {
        if (TextUtils.isEmpty(str)) {
            return "image_default_icon";
        }
        return str;
    }

    protected static void ˏ(ImageView imageView, String str, String str2, String str3, int i, int i2) {
        Context context = null;
        e eVar = new e();
        eVar.ॱॱ = str;
        eVar.ॱ = i;
        eVar.ˋ = i2;
        if (imageView != null) {
            context = imageView.getContext();
        }
        eVar.ˎ = ॱ(context, str2);
        if (!TextUtils.isEmpty(str3)) {
            eVar.ʽ = new b(imageView, str3);
        }
        ˋ(imageView, eVar);
    }

    public static void ˋ(int i, int i2, ImageView imageView, String str) {
        ˏ(imageView, str, null, null, i, i2);
    }

    public static void ˋ(int i, int i2, ImageView imageView, String str, String str2) {
        ˏ(imageView, str, str2, null, i, i2);
    }

    public static void ˏ(int i, int i2, ImageView imageView, String str, String str2, eqz o_eqz, boolean z) {
        if (imageView == null || str == null || str2 == null || o_eqz == null) {
            Logger.ˎ("ImageUtils", "asynLoadImage param is null");
            return;
        }
        Context context = imageView.getContext();
        imageView.setTag(imageView.getId(), str);
        int ˎ = ˎ(context);
        ro ˎ2 = eqy.ˎ((ˎ * i) / 480, (ˎ * i2) / 480, context, str, z);
        if (ˎ2 != null) {
            ˏ(ˎ2, str2, imageView);
            ˎ2.ॱ(new era()).ˏ(new c(imageView, o_eqz, str));
        }
    }

    private static int ˎ(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.densityDpi;
    }
}
